$(function(){           
     formValidate('user_reg_fm','newbutton');
});
/**
 * 注册页面表单验证（邮箱注册、手机号注册、企业注册）
 * @param  {string} fromId 表单id
 * @param  {string} btnId  按钮Id
 * @return {string}        null
 */
function formValidate(fromId,btnId){
    var focusMessage = {
        name:"请输入参赛单位",
        coach: "请输入教练员",
        player: "请输入参赛选手姓名",
        weapons: "请选择参赛剑种",
        sex : "请选择选手性别",
        birthday : "请输入选手出生年月",
        idcard : "请输入选手身份证号码",
        linkperson:"请输入联系人",
        linktel: "请输入联系方式"
    };
    var errorIcon = '<i class="iconfont" title="提示">&#xe67d;</i>';
    $("#" + fromId).validate({
        errorElement: "span",
        onkeyup: function (element) {
            return false;
        },
        onfocusin: function (element) {
            /*var $this = $(element);
            $this.parent('td').next('.validate-tips').text(focusMessage[$this.attr("id")]);
            //$this.removeClass('has-error');*/
            var $this = $(element);
            $this.removeClass('has-error');
            var msg = focusMessage[$this.attr("id")] || '';
            if (msg != '') {
                msg = '<span>' + msg + '</span>';
                $this.parent('td').next('td.validate-tips').html(msg);
            }
        },
        rules: {
            name: {
                required: true,
            },
            coach: {
                required: true
            },
            player: {
            	 required: true
            },
            weapons: {
           	 	required: true
            },
            sex: {
            	required: true
         	},
         	birthday: {
             	 required: true
         	},
         	idcard: {
             	 required: true
         	},
         	linkperson: {
         		required: true
         	},
         	linktel: {
             	 required: true
         	}
        },
        errorClass: "error",
        errorPlacement : function(error, element) {
            var $this = $(element);
            var $tips = $this.parent('td').next('td.validate-tips');
            $tips.html('');
            error.appendTo($tips);
        },
        success : function(label) {
            var $error = $(label);
            $error.html('<i class="iconfont color2ea" title="成功">&#xe67e;</i>');
            $error.parents('tr').find('.has-error').removeClass("has-error"); 
        },
        highlight: function ( element, errorClass, validClass ) {
            var $input = $( element );
            if(!$input.hasClass("has-error")){
                $input.addClass("has-error" ).removeClass( "has-success" );
            }
        },
        messages : {
            name:{
                required: errorIcon + "请输入参赛单位！"
            },
            coach: {
                required: errorIcon + "请输入教练员!"
            },
            player:{
            	required: errorIcon + "请输入参赛选手姓名!"
            },
            weapons:{
            	required: errorIcon + "请选择参赛剑种!"
            },
            sex:{
            	required: errorIcon + "请选择选手性别!"
         	},
         	birthday:{
         		required: errorIcon + "请输入选手出生年月!"
         	},
         	idcard:{
         		required: errorIcon + "请输入选手身份证号码!"
         	},
         	linkperson:{
         		required: errorIcon + "请输入联系人!"
         	},
         	linktel:{
             	 required: errorIcon + "请输入联系方式!"
         	}
        }
    });
}

